<template>
  <RouterView v-if="userStore.wsenv != ''"
    :style="{
      '--pcmain-color': pcmainColor,
      '--pcvice-color': pcviceColor,
      '--primary': pcmainColor,
      '--el-color-primary': pcmainColor,
    }"
  />
  <app-app-update />
  <!-- <app-message v-if="showmessage"/> -->
  <app-error-dialog />
</template>

<script setup>
import { getVersion } from '@/utils/getVersion'
import { getAppPackage } from '@/utils/getAppPackage'
import { onMounted } from 'vue'

const userStore = useUserStore()
const activeverison = ref('')
const packageJs = ref({})
const pcmainColor = ref('#ff7900')
const pcviceColor = ref('#75b5ea')
const showmessage = ref(false)

onMounted(async () => {
  activeverison.value = await getVersion()

  packageJs.value = await getAppPackage() // 获取electron中的package.json内容
  userStore.savepackageJs(packageJs.value)
  userStore.getIps()

  document.title = `${packageJs.value.productName} V${activeverison.value}` //  设置标题为产品名称 + 版本号
  pcmainColor.value = packageJs.value.productColors.pcmainColor //  设置公共主颜色
  pcviceColor.value = packageJs.value.productColors.pcviceColor //  设置公共次颜色
  document.documentElement.style.setProperty('--pcmain-color', pcmainColor.value) //  全局设置公共主颜色变量
  document.documentElement.style.setProperty('--pcvice-color', pcviceColor.value) //  全局设置公共副颜色变量
  showmessage.value = true
  // 设置软件标题
  if (window.SDK && typeof window.SDK.receive === 'function') {
    window.SDK.receive('set-window-title', data => {
      const intervalId = setInterval(() => {
        if (document.title == data.title) {
          clearInterval(intervalId)
        } else {
          document.title = data.title
        }
      }, 1000)
    })
  }

  if (window.SDK && typeof window.SDK.receive === 'function') {
    window.SDK.receive('add-window-model', data => {
      console.log(data)
    })
  }
})
</script>

<style scoped lang="scss">
@font-face {
  font-family: 'PingFangSC';
  src: url('@/assets/font/PingFang-SC-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'AlibabaPuHuiTi_2_55_';
  src: url('@/assets/font/Alibaba_PuHuiTi_2.0_55_Regular_85_Bold.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}

*,
body {
  font-family: PingFangSC;
}

::v-deep .el-select-dropdown__item.is-selected {
  color: var(--pcmain-color) !important;
}

::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

::v-deep .el-radio__input.is-checked .el-radio__inner {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

::v-deep .el-select .el-select__wrapper,
::v-deep .el-input-number .el-input__wrapper,
::v-deep .el-input .el-input__wrapper {
  border-radius: 0 !important;
}

::v-deep .el-switch.is-checked .el-switch__core {
  background-color: var(--pcmain-color);
  border-color: var(--pcmain-color);
}

::v-deep .el-select__wrapper.is-focused {
  box-shadow: 0 0 0 1px var(--pcmain-color) inset;
}
::v-deep .el-button {
  border-radius: 0 !important;
}
</style>

<style>
.el-select-dropdown__item.is-selected {
  color: var(--pcmain-color) !important;
}

.el-dropdown-menu__item:not(.is-disabled):hover,
.el-dropdown-menu__item:not(.is-disabled):focus {
  color: var(--pcmain-color) !important;
}

.hovepcvicecolor:hover {
  background-color: var(--pcmain-color) !important;
  border-color: var(--pcmain-color) !important;
}

.el-input .el-input__wrapper.is-focus {
  border-color: var(--pcmain-color) !important;
  box-shadow: 0 0 0 1px var(--pcmain-color) inset;
}
</style>
